package com.huidian.gitbatchprocessing.ui.enums;

import java.util.Arrays;
import java.util.Optional;

/**
 * 分支操作枚举
 *
 * @author zxb
 * @date 2021/6/21
 */
public enum BranchOperateEnum {
    /**
     * 创建分支枚举
     */
    CREATE_BRANCH((byte) 1, "创建分支"),

    /**
     * 合并分支枚举
     */
    MERGE_BRANCH((byte) 2, "合并分支"),

    /**
     * 切换分支枚举
     */
    CHECKOUT_BRANCH((byte) 3, "切换分支"),

    /**
     * 删除分支枚举
     */
    DELETE_BRANCH((byte) 4, "删除分支");

    private final Byte key;

    private final String name;

    BranchOperateEnum(Byte key, String name) {
        this.key = key;
        this.name = name;
    }

    public static BranchOperateEnum getByKey(byte key) {
        Optional<BranchOperateEnum> first = Arrays.stream(values()).filter(e -> e.getKey().equals(key)).findFirst();
        return first.orElseThrow(() -> new RuntimeException("分支选项对应的操作不存在"));
    }

    public Byte getKey() {
        return key;
    }

    public String getName() {
        return name;
    }

}
